package com.bw.user.interceptor;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class Interceptorr implements HandlerInterceptor {
    @Autowired
    private HttpServletRequest httpServletRequest;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String token = httpServletRequest.getHeader("token");
        if (ObjectUtil.isNull(token)){
            return false;
        }
        /* session.setAttribute("preurl",request.getRequestURI());*/
        StringBuffer url = request.getRequestURL();
        String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getServletContext().getContextPath()).append("/").toString();
        response.sendRedirect("/tb-user/login");  //跳转到您的登录页面，这是路径
        return false;
    }
}
